﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WEALTH.Manager.BaseSystem
{
    public partial class RoleUpdate : BasePage
    {
        ExcuteDao groupment = new ExcuteDao();

        public string strMsg = "", strLink = "", strSessCode = "";
        public int n = 0;

        protected void Page_Load(object sender, EventArgs e)
        {

            strSessCode = Request.QueryString["code"].ToString().Trim();
            if (!IsPostBack)
            {
                Bind();
            }
        }

        public void Bind()
        {
            SqlDataReader dr = null;
            try
            {
                dr = groupment.GetReader(strSessCode);
                if (dr.Read())
                {
                    txtRole_ID.Text = dr["Role_Code"].ToString().Trim();
                    txtRole_Name.Text = dr["Role_Name"].ToString().Trim();
                    rblIsUse.SelectedValue = dr["Role_IsUse"].ToString().Trim();
                    Session["TEMP1"] = "1";

                }
            }
            catch (Exception ex)
            {
                //strLink = "../Error_Page.aspx?code=1&msg=" + publ.GetUrlToSend(publ.GetCatchMsg(errorMsg.ToString().Trim()));
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                    dr = null;
                }
                if (strLink.Length > 0)
                {
                    Response.Redirect(strLink, false);
                }
                txtRole_Name.Focus();
            }


        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string GroupCode = txtRole_ID.Text.Trim();
            string GroupName = txtRole_Name.Text.Trim();
            string PGroupCode = Session["TEMP1"].ToString().Trim();
            string IsUse = rblIsUse.SelectedValue;

            n = groupment.UpdateGroupMenu(GroupCode, GroupName, PGroupCode, IsUse);
            if (n > 0)
            {
                Session["msg"] = "更新角色成功！";
                //Response.Write("<script>top.location.href('../Welcome.aspx?local=System/RoleList.aspx');</script>");
                Response.Write("<script  type='text/javascript'>top.window.location='../Welcome.aspx?local=BaseSystem/RoleList.aspx';</script>");
            }
            else
            {
                ShowMsg("更新角色失败！", 1);
                return;
            }
            return;
        }
    }
}